//
//  ItemDetailView.m
//  仿造淘宝商品详情页
//
//  Created by yixiang on 16/3/25.
//  Copyright © 2016年 yixiang. All rights reserved.
// 商品评论

#import "WHRTGComment.h"
#import "WHRProductCommentCell.h"
#import "UITableView+SDAutoTableViewCellHeight.h"
#import "WHRTGCommentModel.h"


@interface WHRTGComment()

@property (nonatomic , strong) NSMutableArray<WHRTGCommentModel *> *modelsArray;
@property (nonatomic, strong) NSMutableArray *arrayImages;

@end

@implementation WHRTGComment

- (void)setGoodsId:(NSString *)goodsId {
    _goodsId = goodsId;
    [self requestData];
}




- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.modelsArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return [tableView cellHeightForIndexPath:indexPath model:self.modelsArray[indexPath.row] keyPath:@"model" cellClass:[WHRProductCommentCell class] contentViewWidth:SCREEN_WIDTH];
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [self.tableView registerClass:[WHRProductCommentCell class] forCellReuseIdentifier:[WHRProductCommentCell reuseID]];
    WHRProductCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:[WHRProductCommentCell reuseID] forIndexPath:indexPath];
    cell.model = self.modelsArray[indexPath.row];
    
    return cell;
}



- (void)requestData {
    
    ZX_WEAK_SELF
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"typeId"]= _goodsId;
    
    [NetWorkHelp yl_postDataWith:params url:URL_SPLIT(URL_ActivityPrefecture, URL_ActivityPrefecture_commentList) success:^(id respose) {
        
        
        if ([respose[@"header"][@"statusCode"] integerValue] == 200) {
            
            weakSelf.modelsArray = [WHRTGCommentModel mj_objectArrayWithKeyValuesArray:respose[@"body"][@"commentList"]];
            
            [self.tableView reloadData];
            
        } else if ([respose[@"header"][@"statusCode"] integerValue] != 200) {
            
        }
        [self.tableView.mj_header endRefreshing];
        [self.tableView.mj_footer endRefreshing];
        
    } failure:^(NSError *error) {
        
        [self.tableView.mj_header endRefreshing];
        [self.tableView.mj_footer endRefreshing];
        
        
    }];
}



@end
